package cn.tedu.jdbc.Demo;

/**
 * @author Justin Parker
 * @author 2024/8/1 下午11:23
 * @version 1.0
 */

import cn.tedu.jdbc.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/** 查询类 */
public class InquireDemo {
    public static void Inquire(){
        try(Connection connection = DBUtil.getConnection()) {

            String sql = "select * from userinfo;";
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet resultSet = ps.executeQuery();
            while (resultSet.next()){
                System.out.print(resultSet.getString("id")+" |");
                System.out.print(resultSet.getString("username")+" |");
                System.out.print(resultSet.getString("password")+" |");
                System.out.print(resultSet.getString("nickname")+" |");
                System.out.println(resultSet.getString("age")+" |");
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
